package com.yuncheng.spcyApi.schedule;

/**
 * MyTimer定时任务
 */
public class MyTask implements Comparable<MyTask> {
    // 存储任务
    public Runnable runnable;

    // 延迟的时间
    public long time;

    public MyTask(Runnable runnable, long dely) {
        this.runnable = runnable;
        //获取当前时间戳并+dely，作为当前任务实际执行的时间戳
        this.time = dely + System.currentTimeMillis();
    }

    // 重写compareTo方法，让先执行的任务在优先级阻塞队列的队首
    @Override
    public int compareTo(MyTask o) {
        return (int)(this.time - o.time);
    }
}
